//
//  Array.cpp
//  LLTryFightingApp
//
//  Created by jinbang.li on 2024/9/24.
//

#include "Array.hpp"
#include <iostream>
#include <array>

void LLArray::test() {
    std::array<int, 5> myArray = {1,2,3,4,5};
    for (int num : myArray) {
        std::cout << num << " ";
    }
    std::cout << std::endl;
    myArray[0] = 10;
    for (int num : myArray) {
        std::cout << num << " ";
    }
    std::cout << std::endl;
}

void LLDynamicArray::resize(){
    capacity *= 2;
    int *newArr = new int[capacity];
    for (size_t i = 0; i < size; i++) {
        newArr[i] = arr[i];
    }
    delete [] arr;
    arr = newArr;
}
void LLDynamicArray::push_back(int value){
    if (size == capacity) {
        resize();
    }
    arr[size++] = value;
}

void LLDynamicArray::pop_back(){
    if (size == 0) {
        throw std::out_of_range("Array is empty");
    }
    size--;
}
int& LLDynamicArray::operator[](size_t index){
    if (index >=size) {
        throw  std::out_of_range("index out of range");
    }
    return arr[index];
}
size_t LLDynamicArray::getSize() const {
    return size;
}
size_t LLDynamicArray::getCapacity() const {
    return capacity;
}
